package gameoflife.view;

import gameoflife.GameOfLife;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

public class GameOfLifePanel extends JPanel {

	private static final int SIZE = 10;

	private static final long serialVersionUID = 1L;

	private GameOfLife game;

	public GameOfLifePanel(GameOfLife game) {
		this.game = game;
	}

	@Override
	public void paint(Graphics g) {
		super.paint(g);
		drawGrid(g);
	}

	private void drawGrid(Graphics g) {
		for (int row = 0; row < game.getRows(); row++) {
			for (int column = 0; column < game.getColumns(); column++) {
				if (game.isLive(row, column))
					drawLive(g, row + row * SIZE, column + column * SIZE);
				else
					drawDeath(g, row + row * SIZE, column + column * SIZE);
			}
		}
	}

	private void drawLive(Graphics g, int row, int column) {
		g.setColor(Color.black);
		g.fillRect(row, column, SIZE, SIZE);

	}

	private void drawDeath(Graphics g, int row, int column) {
		g.setColor(Color.lightGray);
		g.fillRect(row, column, SIZE, SIZE);
	}

}
